﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>将日期转换为字符串的方法</title>
    <script type="text/javascript">
        function getMyDate(tmpDate){
            var date1,date2;
            date1 = tmpDate.getMonth() + 1 + "";
            if(date1.length<2){
                date1 ="0" + date1;
            }
            date2 = tmpDate.getDate() +"";
            if(date2.length<2){
                date2 = "0" + date2;
            }
            return tmpDate.getFullYear() +"-" + date1 +"0"+date2;
        }
    </script>
</head>
<body>
<input id="Button1" type="button" value="当前日期" onclick="alert(getMyDate(new Date()))" />
</body>
</html>